package cn.me.alphamq.common.model.broker;

import cn.me.alphamq.common.model.broker.meta.MappedFile;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * ConsumeQueue 文件的模型
 *
 * @author f
 */
public class ConsumeQueueFileModel implements MappedFile {

    /**
     * 队列 id
     */
    private Integer id;

    /**
     * 文件名称
     */
    private String fileName;

    /**
     * offset 的最大值
     */
    private Integer offsetLimit;

    /**
     * ConsumeQueue 文件写入数据的偏移量
     */
    private AtomicInteger offset;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public int restSize() {
        return offsetLimit - offset.get();
    }

    @Override
    public String getFileName() {
        return fileName;
    }

    @Override
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Override
    public Integer getOffsetLimit() {
        return offsetLimit;
    }

    @Override
    public void setOffsetLimit(Integer offsetLimit) {
        this.offsetLimit = offsetLimit;
    }

    @Override
    public AtomicInteger getOffset() {
        return offset;
    }

    @Override
    public void setOffset(AtomicInteger offset) {
        this.offset = offset;
    }

    @Override
    public String toString() {
        return "ConsumeQueueFileModel{" +
                "id=" + id +
                ", fileName='" + fileName + '\'' +
                ", offsetLimit=" + offsetLimit +
                ", offset=" + offset +
                '}';
    }
}
